<?php
namespace App\Models;

use EasySwoole\ORM\AbstractModel;

class UserModel extends AbstractModel
{
    protected $tableName = 'users';
    protected $primaryKey = 'id';

    public function getAll(int $page=1, string $keywork=null, int $pageSize=10): array
    {
        $where = [];
        if(!empty($keywork))
        {
            $where['name'] = ['%'. $keywork . '%', 'like'];
        }
        $list = $this->limit($pageSize * ($page -1), $pageSize)
            ->order($this->primaryKey, 'DESC')
            ->withTotalCount()
            ->all($where);
        $total = $this->lastQueryResult()->getTotalCount();
        return ['total'=>$total, 'list'=>$list];
    }
}